/*
	libprop -- library to simulate and measure radio signal propagation
	
	Copyright (C) 2007 Jeffrey Sharkey, jsharkey.org
	
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "source.h"
#include "geom.h"
#include "radio.h"
#include "utils.h"
#include "testcases.h"


#include <stdio.h>
#include <stdlib.h>

#include "gd.h"

#include <iostream>
#include <fstream>

using namespace std;



void error() {
	cout << "Content-Type:image/png" << endl;
	cout << "Error: true" << endl << endl;
	gdImagePtr im = gdImageCreateTrueColor(10, 10);
	gdImageFilledRectangle(im, 0, 0, 10, 10, gdTrueColor(255, 255, 255));
	gdImagePng(im, stdout);
	exit(0);

}


int main(void) {

//cout << "Content-Type:text/plain" << endl << endl;

double towerLat = -1, towerLon = -1, topRightLat = -1, topRightLon = -1, bottomLeftLat = -1, bottomLeftLon = -1;
int detail = -1, r = -1, g = -1, b = -1;
double txHeight = -1, rxHeight = -1, eirp = -1, mhz = -1, txantenna = -1, rxantenna = -1, sens = -1;

// read in all variables from query
char* vars = getenv("QUERY_STRING");
char* var = strtok(vars, ",");
while(var != NULL) {
	if(towerLat == -1) towerLat = atof(var);
	else if(towerLon == -1) towerLon = atof(var);
	else if(bottomLeftLat == -1) bottomLeftLat = atof(var);
	else if(bottomLeftLon == -1) bottomLeftLon = atof(var);
	else if(topRightLat == -1) topRightLat = atof(var);
	else if(topRightLon == -1) topRightLon = atof(var);
	else if(detail == -1) detail = atoi(var);
	else if(r == -1) r = atoi(var);
	else if(g == -1) g = atoi(var);
	else if(b == -1) b = atoi(var);
	else if(txHeight == -1) txHeight = atof(var);
	else if(rxHeight == -1) rxHeight = atof(var);
	else if(eirp == -1) eirp = atof(var);
	else if(mhz == -1) mhz = atof(var);
	else if(txantenna == -1) txantenna = atof(var);
	else if(rxantenna == -1) rxantenna = atof(var);
	else if(sens == -1) sens = atof(var);
	var = strtok(NULL, ",");
}

// check for problems with incoming data bounds

if(topRightLat < 33 || topRightLat > 49 ||
	bottomLeftLat < 33 || bottomLeftLat > 49 ||
	towerLat < 33 || towerLat > 49) error();

if(topRightLon > -102 || topRightLon < -126 ||
	bottomLeftLon > -102 || bottomLeftLat < -126 ||
	towerLon > -102 || towerLon < -126) error();

if(detail < 10) error();

if(r < 0 || r > 255 ||
	g < 0 || g > 255 ||
	b < 0 || b > 255) error();

if(txHeight < 0 || txHeight > 100 ||
	rxHeight < 0 || rxHeight > 100) error();

if(eirp < 0 || eirp > 32768) error();
if(mhz < 150 || mhz > 10000) error();

if(txantenna < 0 || txantenna > 30 ||
	rxantenna < 0 || rxantenna > 30) error();

// load regional elevation data
SourceGroup* sg = new SourceGroup();
//sg->add(new SourceGridFloat(new Convert(), TYPE_ELEV, "80214271.elev/80214271.hdr", false));
//sg->add(new SourceGridFloat(new Convert(), TYPE_ELEV, "63034346/63034346.hdr", false));


Convert* normal = new Convert();

//sg->add(new SourceGridFloat(normal, TYPE_ELEV, "63034346/63034346.hdr", 2809, 5336, -108.34009259127, 43.249999999636, 0.000092592592600001));


sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/00680497/00680497.hdr", 5400, 10801, -122.49999999981, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/00724160/00724160.hdr", 5401, 5401, -120.50009259225, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/01128382/01128382.hdr", 5400, 5401, -121.99999999977, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/01602763/01602763.hdr", 5401, 5401, -118.50009259209, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/01619089/01619089.hdr", 5400, 5401, -120.99999999969, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/01620307/01620307.hdr", 5400, 5401, -122.49999999981, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/02036657/02036657.hdr", 5401, 5401, -119.50009259217, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/02990967/02990967.hdr", 5400, 10801, -124.49999999997, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/03260116/03260116.hdr", 5401, 5401, -117.00009259197, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/05565028/05565028.hdr", 5400, 5401, -121.99999999977, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/05914643/05914643.hdr", 5401, 5401, -119.50009259217, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/06391951/06391951.hdr", 5400, 5401, -120.99999999969, 39.499999999336, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/06455652/06455652.hdr", 5400, 5401, -122.99999999985, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/06602633/06602633.hdr", 5400, 10801, -124.49999999997, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/06978577/06978577.hdr", 5400, 10801, -123.49999999989, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/07301082/07301082.hdr", 5401, 5401, -115.00009259181, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/07545749/07545749.hdr", 5401, 5401, -119.50009259217, 38.499999999256, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/07834411/07834411.hdr", 5400, 5401, -123.49999999989, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/07873207/07873207.hdr", 5401, 5401, -115.00009259181, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/07881913/07881913.hdr", 5401, 5401, -115.50009259185, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/08219950/08219950.hdr", 5401, 5401, -115.00009259181, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/09567258/09567258.hdr", 5400, 5401, -120.99999999969, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/11867483/11867483.hdr", 5400, 5401, -121.49999999973, 41.499999999496, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/12094197/12094197.hdr", 5400, 5401, -121.49999999973, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/12187229/12187229.hdr", 5400, 10801, -123.99999999993, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/12614752/12614752.hdr", 5400, 5401, -121.99999999977, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/13630027/13630027.hdr", 5400, 5401, -121.49999999973, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/13832349/13832349.hdr", 5401, 5401, -120.00009259221, 40.499999999416, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/14556548/14556548.hdr", 5400, 5401, -120.99999999969, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/14815189/14815189.hdr", 5400, 10801, -122.99999999985, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/16013569/16013569.hdr", 5401, 5401, -119.50009259217, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/16042093/16042093.hdr", 5400, 5401, -121.99999999977, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/16626380/16626380.hdr", 5400, 5401, -121.49999999973, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/16654859/16654859.hdr", 5400, 5401, -122.99999999985, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/17320698/17320698.hdr", 5401, 5401, -115.00009259181, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/18934751/18934751.hdr", 5401, 5401, -116.00009259189, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/19584154/19584154.hdr", 5400, 5401, -120.99999999969, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/19593552/19593552.hdr", 5400, 5401, -120.99999999969, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/19665972/19665972.hdr", 5401, 5401, -120.00009259221, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/19671577/19671577.hdr", 5400, 5401, -121.99999999977, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/20000792/20000792.hdr", 5401, 5401, -116.00009259189, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/20979926/20979926.hdr", 5400, 10801, -123.99999999993, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/21100639/21100639.hdr", 5400, 5401, -120.99999999969, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/21937011/21937011.hdr", 5401, 5401, -120.50009259225, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/22815951/22815951.hdr", 5401, 5401, -118.00009259205, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/23062309/23062309.hdr", 5401, 5401, -118.00009259205, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/23553225/23553225.hdr", 5400, 10801, -122.99999999985, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/23643144/23643144.hdr", 5401, 5401, -119.50009259217, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/23934115/23934115.hdr", 5401, 5401, -118.00009259205, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/24197274/24197274.hdr", 5400, 10801, -122.49999999981, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/24484180/24484180.hdr", 5401, 5401, -117.00009259197, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/24615222/24615222.hdr", 5400, 5401, -121.99999999977, 39.499999999336, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/25238768/25238768.hdr", 5401, 5401, -118.00009259205, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/25366891/25366891.hdr", 5400, 5401, -121.49999999973, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/25945975/25945975.hdr", 5400, 5401, -123.49999999989, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/25977226/25977226.hdr", 5400, 5401, -122.99999999985, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/26269509/26269509.hdr", 5401, 5401, -119.50009259217, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/27366948/27366948.hdr", 5400, 5401, -122.99999999985, 38.499999999256, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/27452901/27452901.hdr", 5401, 5401, -117.50009259201, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/27879616/27879616.hdr", 5400, 5401, -120.99999999969, 40.499999999416, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/27974007/27974007.hdr", 1080, 1189, -122.70999999983, 38.869999999285, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/28565190/28565190.hdr", 5401, 5401, -116.50009259193, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/28865336/28865336.hdr", 5400, 5401, -121.99999999977, 40.499999999416, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/29357240/29357240.hdr", 5401, 5401, -117.50009259201, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/29602808/29602808.hdr", 5400, 10801, -122.49999999981, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/30200417/30200417.hdr", 5401, 5401, -115.50009259185, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/30322751/30322751.hdr", 5400, 5401, -121.49999999973, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/31132542/31132542.hdr", 5401, 5401, -116.00009259189, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/31512477/31512477.hdr", 5400, 5401, -121.99999999977, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/31550067/31550067.hdr", 5400, 5401, -122.49999999981, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/31646682/31646682.hdr", 5401, 5401, -119.00009259213, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/31973925/31973925.hdr", 5401, 5401, -115.50009259185, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/32639090/32639090.hdr", 5401, 5401, -117.50009259201, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/33765868/33765868.hdr", 5400, 5401, -120.99999999969, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/33927487/33927487.hdr", 5401, 5401, -116.50009259193, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/34328169/34328169.hdr", 5401, 5401, -120.50009259225, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/34945327/34945327.hdr", 5400, 10801, -125.00000000001, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/35891990/35891990.hdr", 5401, 5401, -116.50009259193, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/35996027/35996027.hdr", 5400, 5401, -121.49999999973, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/36042209/36042209.hdr", 5401, 5401, -117.50009259201, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/36117356/36117356.hdr", 5400, 5401, -123.99999999993, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/36982201/36982201.hdr", 5400, 5401, -120.99999999969, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/37876050/37876050.hdr", 5401, 5401, -119.00009259213, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/38180378/38180378.hdr", 5401, 5401, -120.50009259225, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/38663867/38663867.hdr", 5401, 5401, -115.50009259185, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/38956499/38956499.hdr", 5400, 5401, -121.99999999977, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/39474037/39474037.hdr", 5400, 5401, -121.99999999977, 38.499999999256, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/39604546/39604546.hdr", 5401, 5401, -115.50009259185, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/40298792/40298792.hdr", 5400, 5401, -121.49999999973, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/41205948/41205948.hdr", 5401, 5401, -116.50009259193, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/41286377/41286377.hdr", 5401, 5401, -118.00009259205, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/41372072/41372072.hdr", 5400, 10801, -125.00000000001, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/41794435/41794435.hdr", 5400, 5401, -122.49999999981, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/41924354/41924354.hdr", 5400, 5401, -123.99999999993, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/42297756/42297756.hdr", 5401, 5401, -117.00009259197, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/42467423/42467423.hdr", 5401, 5401, -117.00009259197, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/42586574/42586574.hdr", 5400, 10801, -123.99999999993, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/42593554/42593554.hdr", 5400, 5401, -121.99999999977, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/42776738/42776738.hdr", 5401, 5401, -119.00009259213, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/42999231/42999231.hdr", 5400, 5401, -121.49999999973, 40.499999999416, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/43439245/43439245.hdr", 5401, 5401, -117.50009259201, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/43759764/43759764.hdr", 5401, 5401, -115.50009259185, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/44013467/44013467.hdr", 5401, 5401, -119.50009259217, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/45046833/45046833.hdr", 5400, 5401, -122.49999999981, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/45172273/45172273.hdr", 5401, 5401, -116.50009259193, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/45447314/45447314.hdr", 5401, 5401, -116.00009259189, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/45746018/45746018.hdr", 5401, 5401, -115.50009259185, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/45946007/45946007.hdr", 5401, 5401, -118.00009259205, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/46473728/46473728.hdr", 5401, 5401, -120.50009259225, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/46585525/46585525.hdr", 5400, 5401, -121.99999999977, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/47132229/47132229.hdr", 5401, 5401, -120.50009259225, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/47266135/47266135.hdr", 5401, 5401, -116.50009259193, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/47436049/47436049.hdr", 5401, 5401, -120.50009259225, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/48060923/48060923.hdr", 5401, 5401, -118.50009259209, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/48063632/48063632.hdr", 5400, 5401, -121.99999999977, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/48289180/48289180.hdr", 5400, 5401, -121.99999999977, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/48317549/48317549.hdr", 5400, 5401, -121.99999999977, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/48573665/48573665.hdr", 5400, 5401, -123.49999999989, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/48925941/48925941.hdr", 5400, 10801, -123.99999999993, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/49129061/49129061.hdr", 5400, 5401, -121.49999999973, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/49264197/49264197.hdr", 5401, 5401, -118.50009259209, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/49655574/49655574.hdr", 5400, 5401, -122.99999999985, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/50069594/50069594.hdr", 5401, 5401, -116.00009259189, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/50627803/50627803.hdr", 5401, 5401, -120.00009259221, 41.499999999496, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/51139569/51139569.hdr", 5400, 5401, -120.99999999969, 38.499999999256, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/52229741/52229741.hdr", 5401, 5401, -118.50009259209, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/52488441/52488441.hdr", 5401, 5401, -115.00009259181, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/53370093/53370093.hdr", 5400, 10801, -125.00000000001, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/53601187/53601187.hdr", 5401, 5401, -119.00009259213, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/54020083/54020083.hdr", 5401, 5401, -119.50009259217, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/54139787/54139787.hdr", 5401, 5401, -120.00009259221, 39.499999999336, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/54359836/54359836.hdr", 5400, 5401, -122.49999999981, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/54443731/54443731.hdr", 5401, 5401, -114.50009259177, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/54792101/54792101.hdr", 5401, 5401, -120.00009259221, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/55018501/55018501.hdr", 5401, 5401, -115.00009259181, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/55424986/55424986.hdr", 5401, 5401, -119.50009259217, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/55762742/55762742.hdr", 5400, 5401, -121.49999999973, 39.499999999336, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/55883597/55883597.hdr", 5400, 5401, -121.99999999977, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/55967412/55967412.hdr", 5401, 5401, -119.00009259213, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/56281294/56281294.hdr", 5400, 5401, -120.99999999969, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/56440438/56440438.hdr", 5401, 5401, -120.00009259221, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/56656318/56656318.hdr", 5400, 5401, -123.49999999989, 38.499999999256, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/56916446/56916446.hdr", 5401, 5401, -119.50009259217, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/57463853/57463853.hdr", 5401, 5401, -119.00009259213, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/58437007/58437007.hdr", 5401, 5401, -119.50009259217, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/58841108/58841108.hdr", 5400, 5401, -120.99999999969, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/58956348/58956348.hdr", 5401, 5401, -117.00009259197, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/58959171/58959171.hdr", 5401, 5401, -120.50009259225, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/59117619/59117619.hdr", 5401, 5401, -116.50009259193, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/59205856/59205856.hdr", 5400, 10801, -124.49999999997, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/59687179/59687179.hdr", 5400, 5401, -121.99999999977, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/61508029/61508029.hdr", 5401, 5401, -119.00009259213, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/61805253/61805253.hdr", 5401, 5401, -120.50009259225, 41.499999999496, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/62025741/62025741.hdr", 5401, 5401, -116.50009259193, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/62184682/62184682.hdr", 5401, 5401, -120.50009259225, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/62215875/62215875.hdr", 5401, 5401, -116.00009259189, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/62761047/62761047.hdr", 5401, 5401, -120.00009259221, 38.499999999256, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/64347175/64347175.hdr", 5401, 5401, -115.00009259181, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/64618397/64618397.hdr", 5401, 5401, -118.00009259205, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/64981909/64981909.hdr", 5400, 5401, -123.99999999993, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/65033213/65033213.hdr", 5401, 5401, -120.50009259225, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/65712975/65712975.hdr", 5401, 5401, -120.00009259221, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/65743692/65743692.hdr", 5400, 5401, -121.49999999973, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/65824895/65824895.hdr", 5401, 5401, -120.50009259225, 39.499999999336, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/65954931/65954931.hdr", 5401, 5401, -114.50009259177, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/66104703/66104703.hdr", 5401, 5401, -118.50009259209, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/66537013/66537013.hdr", 5401, 5401, -118.50009259209, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/66615321/66615321.hdr", 5401, 5401, -114.50009259177, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/66780126/66780126.hdr", 5401, 5401, -120.00009259221, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/66987167/66987167.hdr", 5401, 5401, -120.00009259221, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/67134514/67134514.hdr", 5400, 5401, -121.99999999977, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/67379214/67379214.hdr", 5401, 5401, -117.00009259197, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/67752922/67752922.hdr", 5400, 5401, -121.49999999973, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/68552869/68552869.hdr", 5400, 5401, -122.99999999985, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/68579151/68579151.hdr", 5401, 5401, -118.50009259209, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/68689070/68689070.hdr", 5400, 5401, -123.99999999993, 38.499999999256, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/68947195/68947195.hdr", 5401, 5401, -120.00009259221, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/69235623/69235623.hdr", 5401, 5401, -117.50009259201, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/69856724/69856724.hdr", 5401, 5401, -117.50009259201, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/70170699/70170699.hdr", 5400, 5401, -123.99999999993, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/71028846/71028846.hdr", 5400, 10801, -125.00000000001, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/71109069/71109069.hdr", 5401, 5401, -118.00009259205, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/71817014/71817014.hdr", 5401, 5401, -114.50009259177, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/72103972/72103972.hdr", 5401, 5401, -119.00009259213, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/72322807/72322807.hdr", 5401, 5401, -120.50009259225, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/73768291/73768291.hdr", 5400, 10801, -123.49999999989, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/73898613/73898613.hdr", 5400, 5401, -120.99999999969, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/74083980/74083980.hdr", 5400, 10801, -124.49999999997, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/74616100/74616100.hdr", 5401, 5401, -119.00009259213, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/75763141/75763141.hdr", 5400, 10801, -122.49999999981, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/76154670/76154670.hdr", 5400, 5401, -121.49999999973, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/76458127/76458127.hdr", 5400, 5401, -121.49999999973, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/76510235/76510235.hdr", 5401, 5401, -117.00009259197, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/76790337/76790337.hdr", 5401, 5401, -120.50009259225, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/76800583/76800583.hdr", 5400, 10801, -123.49999999989, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/77054392/77054392.hdr", 5401, 5401, -117.00009259197, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/77518000/77518000.hdr", 5401, 5401, -118.00009259205, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/79358337/79358337.hdr", 5401, 5401, -120.00009259221, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/79623424/79623424.hdr", 5401, 5401, -120.00009259221, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/79792482/79792482.hdr", 5400, 5401, -121.49999999973, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/79839873/79839873.hdr", 5401, 5401, -117.00009259197, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/80010111/80010111.hdr", 5400, 5401, -122.49999999981, 38.499999999256, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/80254160/80254160.hdr", 5400, 5401, -123.49999999989, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/80339385/80339385.hdr", 5401, 5401, -118.50009259209, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/80358150/80358150.hdr", 5401, 5401, -118.00009259205, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/80483004/80483004.hdr", 5401, 5401, -120.00009259221, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/81231810/81231810.hdr", 5400, 10801, -122.99999999985, 40.999999999456, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/81491395/81491395.hdr", 5401, 5401, -120.50009259225, 38.499999999256, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/82002645/82002645.hdr", 5401, 5401, -114.50009259177, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/82136143/82136143.hdr", 5401, 5401, -119.00009259213, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/83250817/83250817.hdr", 5401, 5401, -117.50009259201, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/84020088/84020088.hdr", 5400, 5401, -120.99999999969, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/84397490/84397490.hdr", 5401, 5401, -120.50009259225, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/84528245/84528245.hdr", 5400, 5401, -121.49999999973, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/84547464/84547464.hdr", 5400, 5401, -120.99999999969, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/85731079/85731079.hdr", 5400, 10801, -122.99999999985, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/86225526/86225526.hdr", 5401, 5401, -118.50009259209, 37.999999999216, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/86979470/86979470.hdr", 5401, 5401, -118.00009259205, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/86981844/86981844.hdr", 5401, 5401, -120.50009259225, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/87512210/87512210.hdr", 5401, 5401, -114.50009259177, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/87710033/87710033.hdr", 5401, 5401, -118.00009259205, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/88304583/88304583.hdr", 5401, 5401, -120.00009259221, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/90097667/90097667.hdr", 5401, 5401, -120.00009259221, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/90109889/90109889.hdr", 5401, 5401, -117.50009259201, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/90238122/90238122.hdr", 5401, 5401, -116.00009259189, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/90495344/90495344.hdr", 5401, 5401, -119.00009259213, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/90577027/90577027.hdr", 5401, 5401, -116.50009259193, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/91037559/91037559.hdr", 5400, 5401, -120.99999999969, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/91041984/91041984.hdr", 5400, 5401, -120.99999999969, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/91452459/91452459.hdr", 5401, 5401, -119.50009259217, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/91511423/91511423.hdr", 5400, 5401, -123.99999999993, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/91621890/91621890.hdr", 5401, 5401, -120.00009259221, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/91960086/91960086.hdr", 5401, 5401, -120.00009259221, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/92171314/92171314.hdr", 5401, 5401, -116.50009259193, 33.999999998896, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/92848319/92848319.hdr", 5400, 5401, -120.99999999969, 41.499999999496, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/92907064/92907064.hdr", 5400, 5401, -123.49999999989, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/92913400/92913400.hdr", 5401, 5401, -118.50009259209, 32.999999998816, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/93346202/93346202.hdr", 5401, 5401, -117.00009259197, 33.499999998856, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/93554793/93554793.hdr", 5401, 5401, -120.50009259225, 40.499999999416, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/93811554/93811554.hdr", 5401, 5401, -118.50009259209, 34.499999998936, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/94103547/94103547.hdr", 5400, 5401, -121.99999999977, 41.499999999496, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/94951854/94951854.hdr", 5401, 5401, -118.50009259209, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/95002067/95002067.hdr", 5401, 5401, -116.00009259189, 36.999999999136, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/95090289/95090289.hdr", 5401, 5401, -120.00009259221, 36.499999999096, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/96482961/96482961.hdr", 5400, 10801, -123.49999999989, 39.999999999376, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/96509576/96509576.hdr", 5401, 5401, -114.50009259177, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/96728155/96728155.hdr", 5401, 5401, -116.00009259189, 34.999999998976, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/97388485/97388485.hdr", 5401, 5401, -119.00009259213, 37.499999999176, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/97488235/97488235.hdr", 5401, 5401, -116.00009259189, 32.499999998776, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/97598859/97598859.hdr", 5400, 5401, -121.49999999973, 38.499999999256, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/97806449/97806449.hdr", 5401, 5401, -120.50009259225, 38.999999999296, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/98306247/98306247.hdr", 5400, 5401, -121.49999999973, 35.999999999056, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/99177799/99177799.hdr", 5401, 5401, -119.50009259217, 35.499999999016, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "calif/99220202/99220202.hdr", 5401, 5401, -117.50009259201, 34.999999998976, 0.000092592592600001));




sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/07802769/07802769.hdr", 5401, 5401, -110.00009259141, 42.999999999616, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/07939674/07939674.hdr", 5401, 5400, -108.00009259125, 43.499999999656, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/15522436/15522436.hdr", 5401, 5401, -108.00009259125, 42.999999999616, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/27769222/27769222.hdr", 5401, 5401, -109.00009259133, 42.999999999616, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/31564793/31564793.hdr", 5401, 5401, -109.50009259137, 42.999999999616, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/32480620/32480620.hdr", 5401, 5401, -107.50009259121, 42.999999999616, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/44420245/44420245.hdr", 5401, 5400, -110.00009259141, 43.499999999656, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/54787365/54787365.hdr", 5401, 5400, -108.50009259129, 43.999999999696, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/58366835/58366835.hdr", 5401, 5401, -108.50009259129, 42.999999999616, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/59359503/59359503.hdr", 5401, 5400, -109.00009259133, 43.999999999696, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/60583210/60583210.hdr", 5401, 5400, -107.50009259121, 43.499999999656, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/62091713/62091713.hdr", 5401, 5400, -109.50009259137, 43.499999999656, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/73232551/73232551.hdr", 5401, 5400, -108.00009259125, 43.999999999696, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/79231368/79231368.hdr", 5401, 5400, -107.50009259121, 43.999999999696, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/89313062/89313062.hdr", 5401, 5400, -108.50009259129, 43.499999999656, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/95039968/95039968.hdr", 5401, 5400, -109.00009259133, 43.499999999656, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/95566948/95566948.hdr", 5401, 5400, -109.50009259137, 43.999999999696, 0.000092592592600001));
sg->add(new SourceGridFloat(normal, TYPE_ELEV, "wyoming/99858940/99858940.hdr", 5401, 5400, -110.00009259141, 43.999999999696, 0.000092592592600001));




// create image for writing

// one meter in degrees notation
double mlat = 0.0000090175;
double mlon = 0.0000120425;

// pixels is 
int width = (int)((topRightLon - bottomLeftLon) / (mlon * detail));
int height = (int)((topRightLat - bottomLeftLat) / (mlat * detail));

gdImagePtr im = gdImageCreateTrueColor(width, height);
gdImageAlphaBlending(im, 0);
gdImageSaveAlpha(im, 1);

// find central tower location
//Point* tower = new Point((bottomLeftLat + topRightLat) / 2, (bottomLeftLon + topRightLon) / 2, txHeight);
Point* tower = new Point(towerLat, towerLon, txHeight);

// draw across entire image
double degResLat = (topRightLat - bottomLeftLat) / height;
double degResLon = (topRightLon - bottomLeftLon) / width;
int y = height - 1;
for(double lat = bottomLeftLat; lat < topRightLat; lat += degResLat) {
	int x = 0;
	for(double lon = bottomLeftLon; lon < topRightLon; lon += degResLon) {
		// create and test point
		Point* test = new Point(lat, lon, rxHeight);

double loss;
if(sg->contains(test)) {
	loss = pathLoss(tower, test, sg, 0.030, eirp, txantenna+rxantenna, mhz);
} else {
	loss = -1024;
}

		// color if coverage exists
		int color;
		if(loss < sens || loss == DENIED) {
			color = gdTrueColorAlpha(0, 0, 0, 127);
		} else {
			// scale red between 0 and -100
			if(loss > 0) loss = 0;
			double val = (64 * (loss/sens));
			color = gdTrueColorAlpha(r, g, b, (int)val);
		}

		gdImageSetPixel(im, x, y, color);
		x++;
	}
	y--;
}

cout << "Content-Type:image/png" << endl << endl;
gdImagePng(im, stdout);

return 0;

}

